package com.itcast.donkey.popwindow;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.itcast.donkey.R;

/**
 * Created by lanouhn on 16/8/25.
 */
public class PopWindowsMain extends PopupWindow {
    private View view;
    private TextView tv_browse, tv_feedback, tv_set_up;

    public PopWindowsMain(Context context, View.OnClickListener itemOnClickListener) {
        super(context);
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        view = inflater.inflate(R.layout.popwindods_main_activity, null);
        tv_browse = (TextView) view.findViewById(R.id.pop_browse);
        tv_feedback = (TextView) view.findViewById(R.id.pop_feedback);
        tv_set_up = (TextView) view.findViewById(R.id.pop_set_up);

        tv_browse.setOnClickListener(itemOnClickListener);
        tv_feedback.setOnClickListener(itemOnClickListener);
        tv_set_up.setOnClickListener(itemOnClickListener);

        //显示弹出框
        this.setContentView(view);
        this.setWidth(400);
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        //设置弹窗可点击
        this.setFocusable(true);
        //设置弹出窗体的动画效果
        this.setAnimationStyle(R.style.AppTheme);
        ColorDrawable cd = new ColorDrawable(0xb0000000);
        this.setBackgroundDrawable(cd);

        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int height = view.findViewById(R.id.lay_pop).getTop();
                int y = (int) event.getY();
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    if (y < height) {
                        dismiss();
                    }
                }
                return true;
            }
        });
    }
}
